package thread;

class JoinThread  implements Runnable{
	private int x;
	public void run(){
		for (int i = 0; i < 5; i++) {
			System.out.println(Thread.currentThread().getName()+" "+i);
			for (int j = 0; j < 100000; j++) {
				for (int j2 = 0; j2 < 10000; j2++) {
					x=x+j2;		
				}
			
			}
		}
	}
	public static void main(String[] args) throws InterruptedException {
		JoinThread st=new JoinThread();
		Thread st1=new Thread(st,"newThread1");
		Thread st2=new Thread(st,"newThread2");
	for (int i = 0; i < 50; i++) {
		System.out.println(Thread.currentThread().getName()+" "+i);
		if (i==20) {
			st1.start();
			st1.join(1);//join
		}
		
	}	
	}
}